In [1]:
import pandas as pd
import pyflaski as flaski
%matplotlib inline

plotly examples¶

In [2]:
session_file="/pyflaski_sessions/volcano.json"
session, msg = flaski.read_session(session_file)
- Session info -
Flaski: 3.10.20
pyflaski: 26ea2522
App: scatterplot
Items: df, filename, last_modified, pa
In [3]:
pa=session["pa"]
df=pd.read_json(session["df"])
figure=flaski.scatterplot.make_figure(df,pa)
print("Type:", type(figure))
figure.show()
Type: <class 'plotly.graph_objs._figure.Figure'>

manipulating an plotly object with plotly's methods¶

In [4]:
figure.update_layout( title={'text': "this is a real title"})
figure.show()

subplots¶

In [5]:
from plotly.subplots import make_subplots

fig = make_subplots(rows=2, cols=2,subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4"))

for d in figure["data"]:
    fig.append_trace(d,row=1, col=1)
for d in figure["data"]:
    fig.append_trace(d,row=1, col=2)
    
fig.append_trace(figure["data"][0],row=2, col=1)
fig.append_trace(figure["data"][1],row=2, col=2)

fig.update_layout(height=850, width=850,
                  title_text="Multiple Subplots with Titles")

fig.update_xaxes(showgrid=False)
fig.update_yaxes(showgrid=False)

fig.update_xaxes(range=[-3, 3])
fig.update_yaxes(range=[0, 5.5])
fig.update_xaxes(range=[-4, 4],row=1, col=2)

fig.update_layout(template='plotly_white', showlegend=False)


fig.show()

heatmap with plotly¶

In [6]:
session_file="/pyflaski_sessions/heatmap.json"
session, msg = flaski.read_session(session_file)
pa=session["pa"]
df=pd.read_json(session["df"])
figure, clusters_cols, clusters_rows, df_=flaski.heatmap.make_figure(df,pa)
figure.show()
- Session info -
Flaski: 3.10.20
pyflaski: 26ea2522
App: heatmap
Items: filename, last_modified, df, pa

reading the arguments¶

In [7]:
print(type(pa))
for k in list(pa.keys()):
    print(k,":",pa[k])
<class 'dict'>
fig_width : 800
fig_height : 800
xcols : []
xvals : ensembl_gene_id
ycols : []
yvals : ['WT.Rep_1', 'WT.Rep_2', 'WT.Rep_3', 'MUT.Rep_1', 'MUT.Rep_2', 'MUT.Rep_3', 'WT.Rep_4', 'WT.Rep_5', 'WT.Rep_6', 'MUT.Rep_4', 'MUT.Rep_5', 'MUT.Rep_6']
available_rows : []
title : Heatmap
title_size : ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100']
title_size_value : 16
show_labels : ['xticklabels', 'yticklabels']
method : ['single', 'complete', 'average', 'weighted', 'centroid', 'median', 'ward']
method_value : ward
distance : ['euclidean', 'minkowski', 'cityblock', 'seuclidean', 'sqeuclidean', 'cosine', 'correlation', 'hamming', 'jaccard', 'chebyshev', 'canberra', 'braycurtis', 'mahalanobis', 'yule', 'matching', 'dice', 'kulsinski', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'wminkowski']
distance_value : euclidean
col_color_threshold : 
row_color_threshold : 
colorscale : ['aggrnyl', 'agsunset', 'blackbody', 'bluered', 'blues', 'blugrn', 'bluyl', 'brwnyl', 'bugn', 'bupu', 'burg', 'burgyl', 'cividis', 'darkmint', 'electric', 'emrld', 'gnbu', 'greens', 'greys', 'hot', 'inferno', 'jet', 'magenta', 'magma', 'mint', 'orrd', 'oranges', 'oryel', 'peach', 'pinkyl', 'plasma', 'plotly3', 'pubu', 'pubugn', 'purd', 'purp', 'purples', 'purpor', 'rainbow', 'rdbu', 'rdpu', 'redor', 'reds', 'sunset', 'sunsetdark', 'teal', 'tealgrn', 'viridis', 'ylgn', 'ylgnbu', 'ylorbr', 'ylorrd', 'algae', 'amp', 'deep', 'dense', 'gray', 'haline', 'ice', 'matter', 'solar', 'speed', 'tempo', 'thermal', 'turbid', 'armyrose', 'brbg', 'earth', 'fall', 'geyser', 'prgn', 'piyg', 'picnic', 'portland', 'puor', 'rdgy', 'rdylbu', 'rdylgn', 'spectral', 'tealrose', 'temps', 'tropic', 'balance', 'curl', 'delta', 'edge', 'hsv', 'icefire', 'phase', 'twilight', 'mrybm', 'mygbm']
colorscale_value : blues
color_bar_label : 
color_bar_font_size : 10
color_bar_ticks_font_size : 10
color_bar_horizontal_padding : 100
show_clusters : ['row_cluster', 'col_cluster']
robust : 0
color_continuous_midpoint : 
reverse_color_scale : []
lower_value : 
center_value : 
upper_value : 
lower_color : 
center_color : 
upper_color : 
col_dendogram_ratio : 0.15
row_dendogram_ratio : 0.15
dendogram_dist : ['row_dendogram_dist', 'col_dendogram_dist']
add_constant : 
log_transform : ['none', 'log10', 'log2']
log_transform_value : none
zscore : ['none', 'row', 'columns']
zscore_value : none
xaxis_font_size : 10
yaxis_font_size : 10
findrow : []
findrowtype : ['percentile', 'n rows', 'absolute']
findrowtype_value : n rows
findrowup : 
findrowdown : 
download_format : ['png', 'pdf', 'svg']
downloadf : pdf
downloadn : heatmap
session_downloadn : MySession.iheatmap
inputsessionfile : Select file..
session_argumentsn : MyArguments.iheatmap
inputargumentsfile : Select file..

help¶

In [8]:
help(flaski.heatmap.make_figure)
Help on function make_figure in module pyflaski.heatmap:

make_figure(df, pa)
    Generates figure.
    
    Args:
        df (pandas.core.frame.DataFrame): Pandas DataFrame containing the input data.
        pa (dict): A dictionary of the style { "argument":"value"} as outputted by `figure_defaults`.
    
    Returns:
        A Plotly figure.
        A Pandas DataFrame with columns clusters.
        A Pandas DataFrame with rows clusters.
        A Pandas DataFrame as displayed in the the Maptlotlib figure.

In [9]:
help(flaski.heatmap.figure_defaults)
Help on function figure_defaults in module pyflaski.heatmap:

figure_defaults()
    Generates default figure arguments.
    
    Returns:
        dict: A dictionary of the style { "argument":"value"}

In [ ]: